package com.btex.app;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.btex.app.tools.SharedPreferencesUtil;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LanguageActivity extends BaseActivity {

    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.tv_menu)
    TextView mTvMenu;
    @BindView(R.id.rl_title)
    RelativeLayout mRlTitle;
    @BindView(R.id.activity_setting_imag_one)
    ImageView mActivitySettingImagOne;
    @BindView(R.id.activity_setting_imag_one_lin)
    LinearLayout mActivitySettingImagOneLin;
    @BindView(R.id.activity_setting_imag_two)
    ImageView mActivitySettingImagTwo;
    @BindView(R.id.activity_setting_imag_two_lin)
    LinearLayout mActivitySettingImagTwoLin;
    boolean isChinese = true;
    @BindView(R.id.activity_setting_imag_three)
    ImageView mActivitySettingImagThree;
    @BindView(R.id.activity_setting_imag_three_lin)
    LinearLayout mActivitySettingImagThreeLin;
    @BindView(R.id.activity_setting_imag_four)
    ImageView mActivitySettingImagFour;
    @BindView(R.id.activity_setting_imag_four_lin)
    LinearLayout mActivitySettingImagFourLin;
    private SharedPreferencesUtil mSharedPreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_language);
        ButterKnife.bind(this);
        mTvTitle.setText(getString(R.string.c_set));
        mSharedPreferences = SharedPreferencesUtil.getSharedPreferences(this);
        boolean is = mSharedPreferences.getBoolean("ischinese", true);
        String city = mSharedPreferences.getString("city_new", "0");
        isChinese = is;
        if (city.equals("0")) {

            mActivitySettingImagThree.setVisibility(View.INVISIBLE);
            mActivitySettingImagTwo.setVisibility(View.INVISIBLE);
            mActivitySettingImagFour.setVisibility(View.INVISIBLE);
            mActivitySettingImagOne.setVisibility(View.VISIBLE);

        } else if (city.equals("1")) {

            mActivitySettingImagThree.setVisibility(View.INVISIBLE);
            mActivitySettingImagTwo.setVisibility(View.VISIBLE);
            mActivitySettingImagFour.setVisibility(View.INVISIBLE);
            mActivitySettingImagOne.setVisibility(View.INVISIBLE);

        } else if (city.equals("2")) {

            mActivitySettingImagThree.setVisibility(View.VISIBLE);
            mActivitySettingImagTwo.setVisibility(View.INVISIBLE);
            mActivitySettingImagFour.setVisibility(View.INVISIBLE);
            mActivitySettingImagOne.setVisibility(View.INVISIBLE);

        } else {

            mActivitySettingImagThree.setVisibility(View.INVISIBLE);
            mActivitySettingImagTwo.setVisibility(View.INVISIBLE);
            mActivitySettingImagFour.setVisibility(View.VISIBLE);
            mActivitySettingImagOne.setVisibility(View.INVISIBLE);

        }
//
//        if (is) {
//            mActivitySettingImagTwo.setVisibility(View.INVISIBLE);
//            mActivitySettingImagOne.setVisibility(View.VISIBLE);
//        } else {
//            mActivitySettingImagTwo.setVisibility(View.VISIBLE);
//            mActivitySettingImagOne.setVisibility(View.INVISIBLE);
//        }
    }

    @Override
    public void setData() {


    }

    @Override
    public void onClick(View view) {

    }

    @OnClick({R.id.activity_setting_imag_one_lin, R.id.activity_setting_imag_two_lin, R.id.iv_back, R.id.activity_setting_imag_three_lin, R.id.activity_setting_imag_four_lin})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_setting_imag_one_lin:
                if (isChinese) {

                    mSharedPreferences.putString("city_new", "0");
                    return;

                } else {
                    mSharedPreferences.putString("city_new", "0");
                    mSharedPreferences.putString("check", "0");
                    mSharedPreferences.putBoolean("ischinese", true);
                    EventBus.getDefault().post("killActivity");
                    Intent intent = new Intent(this, LoadActivity.class);
                    startActivity(intent);
                    finish();
                }

                setHide();
                mActivitySettingImagOne.setVisibility(View.VISIBLE);
                mSharedPreferences.putBoolean("isEngilsh", false);
                break;

            case R.id.activity_setting_imag_two_lin:

                EventBus.getDefault().post("killActivity");

                if (isChinese) {
                    mSharedPreferences.putString("city_new", "1");
                    mSharedPreferences.putString("check", "0");
                    mSharedPreferences.putBoolean("isEngilsh", true);
                    Intent intent = new Intent(this, LoadActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    return;
                }

                setHide();
                mActivitySettingImagTwo.setVisibility(View.VISIBLE);
                mSharedPreferences.putBoolean("ischinese", false);
                break;

            case R.id.activity_setting_imag_three_lin:

                String city = mSharedPreferences.getString("city_new", "0");
                if (city.equals("2")) {


                } else {

                    mSharedPreferences.putString("city_new", "2");
                    EventBus.getDefault().post("killActivity");
                    mSharedPreferences.putBoolean("ischinese", false);
                    mSharedPreferences.putString("check", "0");
                    Intent intent = new Intent(this, LoadActivity.class);
                    startActivity(intent);
                    finish();

                }

                setHide();
                mActivitySettingImagThree.setVisibility(View.VISIBLE);

                break;
            case R.id.activity_setting_imag_four_lin:

                String city_new = mSharedPreferences.getString("city_new", "0");
                if (city_new.equals("3")) {


                } else {

                    mSharedPreferences.putString("city_new", "3");
                    EventBus.getDefault().post("killActivity");
                    mSharedPreferences.putString("city_new", "3");
                    mSharedPreferences.putBoolean("ischinese", false);
                    mSharedPreferences.putString("check", "0");
                    Intent intent = new Intent(this, LoadActivity.class);
                    startActivity(intent);
                    finish();


                }
                setHide();
                mActivitySettingImagFour.setVisibility(View.VISIBLE);

                break;

            case R.id.iv_back:
                finish();
                break;
        }
    }

    private void setHide() {
        mActivitySettingImagFour.setVisibility(View.INVISIBLE);
        mActivitySettingImagThree.setVisibility(View.INVISIBLE);
        mActivitySettingImagOne.setVisibility(View.INVISIBLE);
        mActivitySettingImagTwo.setVisibility(View.INVISIBLE);
    }
}
